/*******************************************************************************
GNetwork.h

	Author:		LiuDingXi
	e-mail:		liudx@gmail.com
	Date time:	2009-10-10

	Copyright (C) 2009
	All rights reserved.
	
*******************************************************************************/

#ifndef _GNETWORK_H_
#define _GNETWORK_H_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef CALLBACK
#define CALLBACK
#endif

enum // Network Status Notify
{
	NF_DOING,
	NF_CONN_ING,
	NF_SEND_ING,
	NF_RECV_ING,

	NF_DONE,
	NF_CONN_OK,
	NF_SEND_OK,
	NF_RECV_OK,
	NF_DISCONNECT_DONE,

	NF_ERROR,
	NF_INIT_ERROR,
	NF_CONN_ERROR,
	NF_SEND_ERROR,
	NF_RECV_ERROR,
};

typedef void (CALLBACK * NetNotify)(UINT nStatus, DWORD lParam, LPVOID lpObject);

class GNetwork
{
public:
	GNetwork();
	virtual ~GNetwork();
	
public:
	BOOL	Initialize(LPCTSTR szInit, NetNotify pfNotify, LPVOID lpObject);
	BOOL	Uninitialize();

	BOOL	Connect(LPCTSTR szServer, int nPort);
	BOOL	Disconnect();

	BOOL	SendData(LPVOID pData, UINT nBytes);
	BOOL	RecvData(LPVOID pData, UINT nBytes);

public:
	UINT	QueryStatus(DWORD& lParam);

protected:

	NetNotify	m_pfNotify;
	LPVOID		m_lpObject;

	LPVOID		m_pSendData;
	UINT		m_nSendSize;

	LPVOID		m_pRecvData;
	UINT		m_nRecvSize;

	UINT		m_nStatus;
};


#endif//_GNETWORK_H_
